package rentalStore;

import java.rmi.NotBoundException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.naming.NameAlreadyBoundException;

import rentalCompany.CarRentalCompanyRemote;

/**
 *
 * @author 
 */
public class CarRentalStore {

    private static Map<String, CarRentalCompanyRemote> rentals =
            new ConcurrentHashMap<String, CarRentalCompanyRemote>();

    public static void addCarRentalCompany(String name, CarRentalCompanyRemote company)
            throws NameAlreadyBoundException {
        if(rentals.containsKey(name)) {
            throw new NameAlreadyBoundException("The given name (" + name + ") is already bound to a car rental company");
        }
        rentals.put(name, company);
    }

    public static void removeCarRentalCompany(String name) {
        rentals.remove(name);
    }

    public static CarRentalCompanyRemote getCarRentalCompany(String name) 
            throws NotBoundException {
        CarRentalCompanyRemote crc = rentals.get(name);
        if(crc == null) {
            throw new NotBoundException("The given name (" + name + ") is not bound to anything");
        }
        return crc;
    }
    
    public static Map<String, CarRentalCompanyRemote> getRentals() {
        return rentals;
    }
    
    


}
